package com.tx.schedule.util;

import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringUtils implements ApplicationContextAware {
	@Autowired
	public static ApplicationContext applicationContext;

	/**
	 * 根据beanName获取bean对象
	 * 
	 * @param beanName
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <T> T getBean(String beanName) {
		return (T) applicationContext.getBean(beanName);
	}

	/**
	 * 获取指定类型的bean集合
	 * 
	 * @param classType
	 * @return
	 */
	public static <T> Map<String, T> getBean(Class<T> classType) {
		return applicationContext.getBeansOfType(classType);
	}

	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		SpringUtils.applicationContext=applicationContext;
		
	}
}
